﻿using Cache;
using Domain.Entity;
using DtoFw;
using DtoFw.Base;
using DtoFw.Query;
using DtoFw.Result;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service;
using System.Collections.Generic;

namespace SceneEvidenceAPI.Controllers
{
    /// <summary>
    /// 预警
    /// </summary>
    [Route("api/earlywarning")]
    [AllowAnonymous]
    public class EarlyWarningController : BaseController
    {
        private readonly EarlyWarningService _earlyWarningService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="earlyWarningService"></param>
        public EarlyWarningController(EarlyWarningService earlyWarningService)
        {
            _earlyWarningService = earlyWarningService;
        }

        /// <summary>
        /// 处理异常出库
        /// </summary>
        /// <param name="rfidList">物品RFID</param>
        /// <returns>是否入库</returns>
        [HttpPost("get/warn/stockStatus")]
        [AllowAnonymous]
        public BaseGenericResult<bool> GetEvidenceStockStatus([FromBody] List<string> rfidList)
        {
            return _earlyWarningService.GetEvidenceStockStatus(rfidList);
        }

        /// <summary>
        /// 环境监控数据存储
        /// </summary>
        /// <param name="warnEnvironmentEntityList">环境信息</param>
        /// <returns>是否成功</returns>
        [HttpPost("hanle/warn/environment")]
        [AllowAnonymous]
        public BaseGenericResult<bool> HandleWarnEnvironment([FromBody] List<WarnEnvironmentEntity> warnEnvironmentEntityList)
        {
            return _earlyWarningService.HandleWarnEnvironment(warnEnvironmentEntityList);
        }

        /// <summary>
        /// 获取消息分页
        /// </summary>
        /// <returns></returns>
        [HttpPost("get/pager/notification")]
        [AllowAnonymous]
        public BaseGenericResult<Pager<NotificationResult>> QueryParentNotification([FromBody] NotificationPagerReqDto reqDto)
        {
            return _earlyWarningService.QueryParentNotification(reqDto);
        }
        /// <summary>
        /// 获取消息分页
        /// </summary>
        /// <returns></returns>
        [HttpPost("deleteNotificationByIds")]
        public BaseGenericResult<string> DeleteNotificationByIds([FromBody] BaseQuery reqDto)
        {
            return _earlyWarningService.DeleteNotificationByIds(reqDto);
        }
        /// <summary>
        /// 未查看数据数量
        /// </summary>
        /// <returns></returns>
        [HttpPost("get/notificationCount")]
        [AllowAnonymous]
        public BaseGenericResult<int> NotificationCount([FromBody] BaseOperator reqDto)
        {
            return _earlyWarningService.NotificationCount(reqDto);
        }

        /// <summary>
        /// 清空个人未查看数量
        /// </summary>
        /// <returns></returns>
        [HttpGet("get/ClearNotificationCount")]
        [AllowAnonymous]
        public BaseGenericResult<bool> ClearNotificationCount()
        {
            var user = TokenHelper.GetTokenInfo<TokenData>(User);
            return _earlyWarningService.ClearNotificationCount(user.UserId);
        }

        #region 查询：预警信息

        /// <summary>
        /// 查询：物品未绑定
        /// </summary>
        /// <param name="warnRequestDto">参数</param>
        /// <returns>信息</returns>
        [HttpPost("get/warn/unbound")]
        [AllowAnonymous]
        public BaseGenericResult<Pager<WarnBindDto>> QueryWarnEvidenceUnbound([FromBody] WarnRequestDto warnRequestDto)
        {
            return _earlyWarningService.QueryWarnEvidenceUnbound(warnRequestDto);
        }

        /// <summary>
        /// 查询：未及时入库
        /// </summary>
        /// <param name="warnRequestDto">参数</param>
        /// <returns>信息</returns>
        [HttpPost("get/warn/overtimeStock")]
        [AllowAnonymous]
        public BaseGenericResult<Pager<WarnBindDto>> QueryWarnOvertimeStock([FromBody] WarnRequestDto warnRequestDto)
        {
            return _earlyWarningService.QueryWarnOvertimeStock(warnRequestDto);
        }

        /// <summary>
        /// 查询：未及时回库
        /// </summary>
        /// <param name="warnRequestDto">参数</param>
        /// <returns>信息</returns>
        [HttpPost("get/warn/overtimeRevert")]
        [AllowAnonymous]
        public BaseGenericResult<Pager<WarnBindDto>> QueryWarnOvertimeRevert([FromBody] WarnRequestDto warnRequestDto)
        {
            return _earlyWarningService.QueryWarnOvertimeRevert(warnRequestDto);
        }

        /// <summary>
        /// 查询：出库异常
        /// </summary>
        /// <param name="warnRequestDto">参数</param>
        /// <returns>信息</returns>
        [HttpPost("get/warn/stock")]
        [AllowAnonymous]
        public BaseGenericResult<Pager<WarnBindDto>> QueryWarnEvidenceStock([FromBody] WarnRequestDto warnRequestDto)
        {
            return _earlyWarningService.QueryWarnEvidenceStock(warnRequestDto);
        }

        /// <summary>
        /// 查询：环境异常
        /// </summary>
        /// <param name="warnRequestDto">参数</param>
        /// <returns>信息</returns>
        [HttpPost("get/warn/environment")]
        [AllowAnonymous]
        public BaseGenericResult<Pager<WarnEnvironmentDto>> QueryWarnEnvironment([FromBody] WarnEnvironmentRequestDto warnRequestDto)
        {
            return _earlyWarningService.QueryWarnEnvironment(warnRequestDto);
        }

        /// <summary>
        /// 查询：保存超期
        /// </summary>
        /// <param name="warnRequestDto">参数</param>
        /// <returns>信息</returns>
        [HttpPost("get/warn/overtimeSave")]
        [AllowAnonymous]
        public BaseGenericResult<Pager<WarnBindDto>> QueryWarnOvertimeSave([FromBody] WarnRequestDto warnRequestDto)
        {
            return _earlyWarningService.QueryWarnOvertimeSave(warnRequestDto);
        }

        /// <summary>
        /// 查询：库容爆仓
        /// </summary>
        /// <param name="warnRequestDto">参数</param>
        /// <returns>信息</returns>
        [HttpPost("get/warn/stockQuantity")]
        [AllowAnonymous]
        public BaseGenericResult<Pager<WarnStockQuantityDto>> QueryWarnStockQuantity([FromBody] WarnStockQuantityRequestDto warnRequestDto)
        {
            return _earlyWarningService.QueryWarnStockQuantity(warnRequestDto);
        }

        #endregion  查询：预警信息

        [HttpPost("GetTest")]
        public bool GetTest()
        {
            return true;
        }

    }
}
